// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Moving Block Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 62 : TYPE_MOVINGBLOCK

// Function declarations
reserve function MovingBlock_DebugDraw
reserve function MovingBlock_DebugSpawn

// Static Values

// Tables

function MovingBlock_DebugDraw
	DrawSprite(0)
end function


function MovingBlock_DebugSpawn
	CreateTempObject(TypeName[Moving Block], 0, object.xpos, object.ypos)
end function


event ObjectMain
	switch object.state
	case 0
		if object[-1].propertyValue == 1
			object.state = 1
			object.priority = PRIORITY_ACTIVE
		end if
		break
	case 1
		if object.value0 < 0x38A0000
			object.value0 += 0x10000
			object.xpos += 0x10000
			object.xvel = 0x10000
		else
			object.xvel = 0
			object.priority = PRIORITY_ACTIVE_BOUNDS
			object.state++
		end if
		break
	end switch
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		CheckEqual(object[currentPlayer].state, PlayerObject_HandleMonikaTeleport)
		temp2 = checkResult
		CheckLower(object[0].value1, 20)
		temp2 &= checkResult
		if temp2 == 0		
			BoxCollisionTest(C_BOX, object.entityPos, -32, -26, 32, 26, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			if checkResult == 1
				object[currentPlayer].xpos += object.xvel
			end if
		end if
		if object[currentPlayer].state == PlayerObject_HandleMonikaTeleport
			if object[0].value1 >= 17
				BoxCollisionTest(C_TOUCH, object.entityPos, -32, -26, 32, 26, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
				if checkResult == 1
					if object[currentPlayer].xpos > object.xpos
						object[currentPlayer].ixpos = object[currentPlayer].collisionLeft
						FlipSign(object[currentPlayer].xpos)
						object[currentPlayer].xpos += 0x320000
						object[currentPlayer].xpos += object.xpos
						if object[currentPlayer].xvel < 0
							object[currentPlayer].pushing = 2
							object[currentPlayer].xvel = 0
							object[currentPlayer].speed = 0
						end if
					else
						object[currentPlayer].ixpos = object[currentPlayer].collisionRight
						FlipSign(object[currentPlayer].xpos)
						object[currentPlayer].xpos -= 0x320000
						object[currentPlayer].xpos += object.xpos
						if object[currentPlayer].xvel > 0
							object[currentPlayer].pushing = 2
							object[currentPlayer].xvel = 0
							object[currentPlayer].speed = 0
						end if
					end if
				end if
			end if
		end if
	next
end event


event ObjectDraw
	DrawSprite(0)
end event


event ObjectStartup
	LoadSpriteSheet("SYZ/Objects.gif")
	SpriteFrame(-32, -26, 64, 52, 119, 99)
	SetTableValue(TypeName[Moving Block], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(MovingBlock_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(MovingBlock_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
